Repository navigation
feat(agents): 提示可以带文件和图片附件,按 ACP 的方式分成图片和文件链接(API-45 0 内补充) - #224
Conversation
清单 agents[].native 新增可选 imageTypes;agents.prompt 新增可选 images [{path}],
Core 按文件开头字节判断类型并检查数量和总大小,didPrompt 带 images [{mimeType, path}]。
四种官方 SDK 新增图片处理方法,没有实现时这一回合以 failed 结束。
更新记录把已合入的 #223 移到 2026-11-28 时间线。
agents.prompt 的 images 改成 attachments:用户选择、粘贴或拖入的文件、文件夹和图片,
最多 64 个,只传路径、不限大小。Core 按文件开头字节把 Agent 在 native.imageTypes
里声明的类型当作图片,其余(含文件夹、空文件、读不了的文件)当作文件链接;
didPrompt 带 {type, path, name, uri, mimeType?}。错误码改为 agents.invalidAttachment、
agents.tooManyAttachments。四种 SDK 改为 prompt_attachments,没有实现时文件链接以
[@name](uri) 并进正文交给 prompt,带图片的回合失败;fixture 补充 Agent plain。
There was a problem hiding this comment.
Devin Review found 2 potential issues.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| export function attachmentLink(attachment) { | ||
| return `[@${attachment.name}](${attachment.uri})`; | ||
| } |
There was a problem hiding this comment.
🟡 Broken attachment links for bracketed filenames
When a filename contains an unmatched ], attachmentLink inserts it unescaped into the Markdown label. The closing bracket breaks the link, leaving the agent with plain text instead of an attachment link.
Learn more
The SDK turns file attachments into Markdown links for handlers that only accept prompt text. The filename goes into the label unchanged, so an unmatched closing bracket ends the label before the destination. This also affects Go Link, Java link, and Rust link. The parenthesized destination also needs protection from literal parentheses in a file URI.
Example: Attaching draft].md produces [@draft].md](file:///work/draft%5D.md), which a Markdown parser reads as plain text even though the URI is valid.
Recommended fix: Escape Markdown metacharacters in the label and use a destination representation that preserves the URI without letting literal parentheses end the link. Add shared fixture cases for brackets and unbalanced parentheses.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if !file.is_absolute() { | ||
| return Err(invalid()); | ||
| } | ||
| let metadata = std::fs::metadata(file).map_err(|_| invalid())?; |
There was a problem hiding this comment.
🟡 Special files accepted as attachments
When a user attaches a Unix socket or named pipe, attachment accepts it as a file link. The prompt starts a turn instead of returning agents.invalidAttachment.
| let metadata = std::fs::metadata(file).map_err(|_| invalid())?; | |
| let metadata = std::fs::metadata(file).map_err(|_| invalid())?; | |
| if !metadata.is_file() && !metadata.is_dir() { | |
| return Err(invalid()); | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
“宿主方法(按 API 编号)”表给 5 个 PR 补了 13 行,都是给已有方法或通知加字段、改校验时漏登记的: - #151:workspace/listContexts、workspace/getContext(authority 新增 platform),functions/invoke(转发远程工作区上下文的调用) - #184:API-11 的 7 个方法(路由前严格校验参数;workspace/create 的 kind 新增 symlink 与 linkTarget) - #188:editor/registerProviders(新增 colorDecorations) - #198:editor/registerActions(actionIcons 新增 4 个导航图标 token) - #224:agents/didPrompt(有附件时带 attachments) 统一写法:方法列只写方法名,补了什么写在协议列的括号里(#193 的 openHTML、openExternal,#23、#128 的 run/start,#128 的 prepareRun);同一个方法的各行排在一起,首次记录在前。 表格说明、维护第 3 步和 API PR 提交指南第 4 步写明:给已有方法或通知加参数、返回字段或取值,或改执行、校验行为,都在索引另加一行;API 总表不加行,用途、权限或协议变了就改原来那一行。
* docs(plugins): 协议更新记录把已合入的 PR 移进时间线并回填日期(#222) “待合入”一节的 20 条记录(含 #224)对应的 PR 都已合入 main,按 UTC 合入日期改成时间线表格行,原文逐句保留,只删去“合入日期在合并时补齐” 之类的占位句;#193 已在时间线里,删去重复的待合入条目。新增 2026-11-24、 2026-11-22 两个日期分组。 - 回填“按协议查首次出现”的市场增量索引 schemaVersion 0(#187)、 toolchainProviders 1 与 litheToolchains 1(#182),以及“宿主方法 (按 API 编号)”里 #194、#190、#183、#151 的 18 个方法日期。 - 补录改了契约却没有登记的 #177、#117、#26。 - #207 的修改人按 PR 作者改为 devin-ai-integration[bot]。 - 时间线表头和维护说明统一用“改动”;转义 #133 行内代码里的竖线, 避免表格多出一列。 * docs(plugins): 已有宿主方法加字段也在方法表补行,统一方法表写法(#222) “宿主方法(按 API 编号)”表给 5 个 PR 补了 13 行,都是给已有方法或通知加字段、改校验时漏登记的: - #151:workspace/listContexts、workspace/getContext(authority 新增 platform),functions/invoke(转发远程工作区上下文的调用) - #184:API-11 的 7 个方法(路由前严格校验参数;workspace/create 的 kind 新增 symlink 与 linkTarget) - #188:editor/registerProviders(新增 colorDecorations) - #198:editor/registerActions(actionIcons 新增 4 个导航图标 token) - #224:agents/didPrompt(有附件时带 attachments) 统一写法:方法列只写方法名,补了什么写在协议列的括号里(#193 的 openHTML、openExternal,#23、#128 的 run/start,#128 的 prepareRun);同一个方法的各行排在一起,首次记录在前。 表格说明、维护第 3 步和 API PR 提交指南第 4 步写明:给已有方法或通知加参数、返回字段或取值,或改执行、校验行为,都在索引另加一行;API 总表不加行,用途、权限或协议变了就改原来那一行。
概述 / Summary
API-45(Agent)的
agents0 内补充:用户可以在 Agent 对话的提示里插入、粘贴或拖入文件、文件夹和图片,交给 Agent CLI。做法照 ACP 客户端发提示内容的方式:附件只传路径、不限大小,CLI 像读用户点名的文件那样自己去读。Core 把附件分成两类:
image内容块;resource_link,后端把它写成[@名称](file:///…)放进提示正文。agents[].native新增可选imageTypes,取值是image/png、image/jpeg、image/gif、image/webp中不重复的若干项。Agent 目录条目同名带出。没声明时所有附件都按文件链接传。agents.prompt新增可选attachments: [{path}]。agents/didPrompt在有附件时带attachments,没有附件时和以前一样。{type: "image", path, name, uri, mimeType};{type: "file", path, name, uri};uri是路径的file:URI,文件夹以/结尾;name是文件名或文件夹名。没有新增能力版本、协议版本、宿主方法或宿主通知。旧 Core 以
plugin.manifest.invalid拒绝声明了imageTypes的清单,也拒绝带attachments的agents.prompt。本 PR 的第一个提交(68b19cf)按“只收图片、最多 8 张、合计 10 MiB”实现;第二个提交(ca60f3e)按评审意见改成上面的附件模型:图片和文件走同一套逻辑,不限大小。两个提交一起看即可,最终行为以本描述为准。
方法与命令 / Methods and commands
没有新增插件宿主方法或宿主通知,只给已有的一条命令和一条通知加了可选字段:
agents.prompt(平台宿主命令,新增可选attachments)agents/didPrompt(已有通知,新增可选attachments)主要改动 / Changes
rust/crates/plugin-agents/src/lib.rs解析并校验native.imageTypes(只认四种类型、不重复、区分大小写),Agent 目录条目带出imageTypes。rust/crates/agent-runtime/src/live.rsagents.prompt依次检查正文长度、附件个数、会话、逐个附件(绝对路径、存在),全部通过才开始回合;url::Url::from_file_path/from_directory_path算出uri(新增依赖url,工作区里已有同版本);agents.invalidAttachment:不是绝对路径或路径不存在;agents.tooManyAttachments:超过 64 个;agents.invalidPrompt的说明改为“正文超过 1 MiB,或没有附件时正文为空”。prompt,带附件的走新方法。后端没有实现新方法时:全是文件链接的提示按“正文、空行、每行一个[@名称](uri)”交给prompt;带图片的提示这一回合以failed结束。AgentAttachment {mime_type, path, name, uri}、is_image()、link()、text_with_links,AgentSession::prompt_attachments默认按上面的规则处理;AgentAttachment、IsImage()、Link()、TextWithLinks,可选接口AgentAttachmentPrompter.PromptAttachments;promptAttachments(turn, text, attachments),导出attachmentLink、textWithLinks,index.d.ts新增AgentAttachment;AgentAttachment(含静态textWithLinks),AgentSession.promptAttachments是默认方法。plugin-agents:image_types_are_distinct_known_types_and_reach_the_catalog(重复值、image/svg+xml、IMAGE/PNG都被拒绝);catalog_entry_hides_session_functions确认没声明时目录条目不带imageTypes。agent-runtime:a_prompt_carries_attachments_as_images_or_file_links。set_len撑到 64 MiB 的 png 仍是图片(不限大小);文件夹是以/结尾的文件链接;uri里转义成%20。agents/native-session.json:带一张图片和一个文件链接的didPrompt;新增 Agentplain,测试后端给它的会话只实现prompt,用来锁定四种 SDK 的默认处理(文件链接并进正文、空正文只留链接、带图片的回合失败)。四种 SDK 的测试都读这份 fixture。shared/plugins/contract/v1/README.md:native 声明、agents.prompt参数与拒绝码、didPrompt的attachments和后端的处理方式(图片按 CLI 的格式传,CLI 的模型要更小的图片时缩小而不是让回合失败;文件链接写成[@名称](uri)),并说明宿主把粘贴的图片放在平台缓存目录;plugin-manifest.schema.json:native.imageTypes;reference/domains/agents.md(中英)、reference/capabilities-and-versions.md(中英)、reference/api-catalog.md(didPrompt两行)、rust/contracts/rust-core-api.md(agents.prompt一行);reference/protocol-changelog.md:本 PR 的待合入条目;已合入的 feat(agents): Agent 资源库统一管理指令、技能、MCP 服务器和 Hooks,并逐条列出调用(API-45 0 内补充) #223 移到 2026-11-28 时间线。验证 / Verification
cargo test -p lithe-agent-runtime -p lithe-plugin-agents:通过(agent-runtime28 个,plugin-agents18 个)。cargo clippy -p lithe-agent-runtime -p lithe-plugin-agents --all-targets -- -D warnings、cargo fmt --all -- --check:通过。cargo fmt --check、cargo clippy --all-targets -- -D warnings、cargo test;Gogofmt -l、go vet、go test;Nodenode --test(94 个)和tsc类型测试;Javamvn test(85 个):都通过。node shared/plugins/scripts/sdk-e2e.mjs:通过。node shared/plugins/scripts/verify-docs.mjs:通过。跟进 / Follow-up
turn/start的localImage;Claude Code 图片发 base64 图片块,超过模型限制时缩小;两者的文件链接都写进正文。PINNED_CORE_REVISION换到 main 上的合入提交。